import jdbc.DBUtil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo5 {
    public static void main(String[] args) {
        try (Connection connection= DBUtil.getConnection();){
            Statement statement= connection.createStatement();
            String sql="SELECT t.name,t.salary,t.title,c.name,c.floor\n" +
                    "FROM teacher t,class c\n" +
                    "WHERE t.id=c.teacher_id\n" +
                    "AND t.name='王克晶'";
            ResultSet rs=statement.executeQuery(sql);
            while (rs.next()){
                String tname=rs.getString(1);
                int tsalary=rs.getInt(2);
                String ttitle=rs.getString(3);
                String cname=rs.getString(4);
                int cfloor=rs.getInt(5);
                System.out.println(tname+" "+tsalary+" "+ttitle+" "+cname+" "+cfloor);
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
